1 ========================================================================
2 VBASPNETPrintPartOfPage Overview
3 ========================================================================
5 /////////////////////////////////////////////////////////////////////////////
8 The project illustrates how to print a specific part of a page.
9 A web form page will contain many parts and some of them need not
10 print for a page, such as button controls, you can not click them
11 in print page, So this sample provides a method to avoid print
12 needless part of page.
14 /////////////////////////////////////////////////////////////////////////////
17 Please follow these demonstration steps below.
19 Step 1: Open the VBASPNETPrintPartOfPage.sln.
21 Step 2: Expand the VBASPNETPrintPartOfPage web application and press
22 Ctrl + F5 to show the Default.aspx.
24 Step 3: You will see many parts of Default.aspx page, There are one "print this
25 page" button and four CheckBoxes in the middle of page.
27 Step 4: Choose the CheckBox to select which part of the page you want to print
28 , then click the Button control to print current page. If you do not
29 have an available printer, Choose the MicroSoft XPS Document Writer to
30 test this sample. You can see the part of page print with .xps
31 file, except for the title of web page.
33 Step 5: Validation finished.
35 /////////////////////////////////////////////////////////////////////////////
38 Step 1. Create a VB "ASP.NET Empty Web Application" in Visual Studio 2010 or
39 Visual Web Developer 2010. Name it as "VBASPNETPrintPartOfPage".
41 Step 2. Add a web form in the root direcory, named it as "Default.aspx".
43 Step 3. Add a "image" folder in the root direcory, add a picture you want
46 Step 4. Create some tables in Default.aspx,and you can fill them with html
47 elements such as image, text, control , etc.
49 Step 5. Define some public strings to store html tag and deposite them in
52 'define some stirngs,use to cut of html code
53 Public printImageBegin As String
54 Public printImageEnd As String
56 'check the status of CheckBox,set div elements.
57 If CheckBox2.Checked Then
58 printImageBegin = String.Empty
59 printImageEnd = String.Empty
61 printImageBegin = enablePirnt
62 printImageEnd = endDiv
66 Step 6. Use JavaScript code to print currently page depend on the status of
67 CheckBox, assign JavaScript function to button's onclick event.The
70 <style type="text/css" media="print">
76 <script type="text/javascript">
77 function print_page() {
83 Step 7. Build the application and you can debug it.
84 /////////////////////////////////////////////////////////////////////////////
87 MSDN: window.print function
88 http://msdn.microsoft.com/en-us/library/ms536672(VS.85).aspx
91 http://msdn.microsoft.com/en-us/library/ms531209(VS.85).aspx
92 /////////////////////////////////////////////////////////////////////////////